import socket
from bdtime import tt
import tools

# server_addr = ('192.168.2.12', 8080)

#client 发送端
client_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
CODING_TYPE = tools.get_coding_type()
SERVER_PORT = 8000
SERVER_IP = tools.get_host_ip()
# SERVER_IP = ""
server_addr = (SERVER_IP, SERVER_PORT)  # 接收方 服务器的ip地址和端口号
client_addr = ('', 4111)


def main():
    udp = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    udp.bind(client_addr)

    while 1:
        send_data = f'hahahha {tt.now(3)}'

        if 1:
            print('~~~~~~ 发送一次数据', tt.now(1))
            tt.sleep(1)

        udp.sendto(send_data.encode('utf-8'), server_addr)
        recv_data = udp.recvfrom(1024)
        print('---- 收到数据: ', recv_data)

        if tt.stop_alt('s'):
            break

    udp.close()

if __name__ == '__main__':
    main()